This notebook demonstrates the nuts and bolts of EffTox, the technical details rather than the general user interface. For example, I use it to check calculations in implementations in other languages. For a general EffTox usage tutorial, use EffTox.ipynb.
In [1]:
import numpy as np
In [2]:
from clintrials.dosefinding.efftox import _pi_E, _pi_T, _pi_ab, _L_n, scale_doses
In the Matchpoint trial, the daily doses of Ponatinib under investigation were:
In [3]:
real_doses = [7.5, 15, 30, 45]
In [4]:
scaled_doses = scale_doses(real_doses)
In [5]:
scaled_doses
Out[5]:
Create some notional values for the two coefficients in the toxicity logit:
In [6]:
alpha0 = np.array([0.0, 1.0, 0.2])
alpha1 = np.array([1.0, -0.5, -1.0])
In [7]:
_pi_T(scaled_doses[1], alpha0, alpha1)
Out[7]:
In [8]:
_pi_T(scaled_doses[3], alpha0, alpha1)
Out[8]:
Create some notional values for the three coefficients in the efficacy logit:
In [9]:
beta0 = np.array([-0.5, -1.0, 0.2])
beta1 = np.array([-1.0, -2.0, 1.0])
beta2 = np.array([0.1, 0.2, -0.1])
In [10]:
_pi_E(scaled_doses[0], beta0, beta1, beta2)
Out[10]:
In [11]:
_pi_E(scaled_doses[2], beta0, beta1, beta2)
Out[11]:
Create some notional values for psi
In [12]:
psi = np.array([-5.0, 0.7, 5.0])
Join it all up
In [13]:
_pi_ab(scaled_doses[0], 0, 1, alpha0, alpha1, beta0, beta1, beta2, psi)
Out[13]:
In [14]:
_pi_ab(scaled_doses[2], 1, 1, alpha0, alpha1, beta0, beta1, beta2, psi)
Out[14]:
Now create some notional cases: 1N 2E 3T, using the nomenclature of Implementing the EffTox dose-finding design in the Matrchpoint trial, by Brock et al.
In [15]:
X = [(scaled_doses[0], 0, 0), (scaled_doses[1], 0, 1), (scaled_doses[2], 1, 0)]
Calculate the compound likelihood under the parameter combinations
In [16]:
_L_n(X, alpha0, alpha1, beta0, beta1, beta2, psi)
Out[16]:
What do these "nuts and bolts" contribute to?
In [17]:
from clintrials.dosefinding.efftox import efftox_get_posterior_probs, efftox_get_posterior_params
In [18]:
cases = [(1, 0, 0), (2, 0, 1), (3, 1, 0)]
In [19]:
from scipy.stats import norm
In [20]:
mu_t_mean, mu_t_sd = -5.4317, 2.7643
beta_t_mean, beta_t_sd = 3.1761, 2.7703
mu_e_mean, mu_e_sd = -0.8442, 1.9786
beta_e_1_mean, beta_e_1_sd = 1.9857, 1.9820
beta_e_2_mean, beta_e_2_sd = 0, 0.2
psi_mean, psi_sd = 0, 1
priors = [
norm(loc=mu_t_mean, scale=mu_t_sd),
norm(loc=beta_t_mean, scale=beta_t_sd),
norm(loc=mu_e_mean, scale=mu_e_sd),
norm(loc=beta_e_1_mean, scale=beta_e_1_sd),
norm(loc=beta_e_2_mean, scale=beta_e_2_sd),
norm(loc=psi_mean, scale=psi_sd),
]
In [21]:
np.random.seed(123)
probs, thing = efftox_get_posterior_probs(cases, priors, scaled_doses, tox_cutoff=0.4, eff_cutoff=0.45, n=10**6)
In [22]:
prob_tox, prob_eff, prob_acc_tox, prob_acc_eff = zip(*probs)
In [23]:
prob_tox
Out[23]:
In [24]:
prob_acc_tox
Out[24]:
In [25]:
prob_eff
Out[25]:
In [26]:
prob_acc_eff
Out[26]:
Warning: this takes a while and peaks memory usage (on my machine) at roughly 1Gb
In [46]:
np.random.seed(123)
probs, thing = efftox_get_posterior_probs(cases, priors, scaled_doses, tox_cutoff=0.4, eff_cutoff=0.45, n=10**7)
In [48]:
prob_tox, prob_eff, prob_acc_tox, prob_acc_eff = zip(*probs)
In [49]:
prob_tox
Out[49]:
In [50]:
prob_acc_tox
Out[50]:
In [51]:
prob_eff
Out[51]:
In [52]:
prob_acc_eff
Out[52]:
In [54]:
efftox_get_posterior_params(cases, priors, scaled_doses, n=10**7)
Out[54]:
In [ ]: